{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import tarfile\n",
    "\n",
    "def recursive_files(dir_name='.', ignore=None):\n",
    "    for dir_name,subdirs,files in os.walk(dir_name):\n",
    "        if ignore and os.path.basename(dir_name) in ignore:\n",
    "            continue\n",
    "        for file_name in files:\n",
    "            if ignore and file_name in ignore:\n",
    "                continue\n",
    "            yield os.path.join(dir_name, file_name)\n",
    "def make_tar_file(dir_name='.', target_file_name='workspace_archive.tar', ignore=None):\n",
    "    tar = tarfile.open(target_file_name, 'w')\n",
    "    for file_name in recursive_files(dir_name, ignore):\n",
    "        tar.add(file_name)\n",
    "    tar.close()\n",
    "dir_name = '.'\n",
    "target_file_name = 'workspace_archive.tar'\n",
    "# List of files/directories to ignore\n",
    "ignore = {'.ipynb_checkpoints', '__pycache__', target_file_name}\n",
    "make_tar_file(dir_name, target_file_name, ignore)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
